package com.ls.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ls.domain.Answer;
import com.ls.domain.Message;
import com.ls.domain.Report;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AnswerMapper extends BaseMapper<Answer> {

    @Select("SELECT report.id, report.report_name, report.report_question, report.report_date\n" +
            "FROM report, student, answer\n" +
            "WHERE report.id = answer.rid AND student.id = answer.sid\n" +
            "AND student.id = #{sid} AND answer.answer_finish = 0\n" +
            "LIMIT #{startIndex},#{pageSize};")
    List<Report> selectReportBySid(Integer sid, int startIndex, int pageSize);

    @Select("SELECT COUNT(*)\n" +
            "FROM report, student, answer\n" +
            "WHERE report.id = answer.rid AND student.id = answer.sid\n" +
            "AND student.id = #{sid} AND answer.answer_finish = 0;")
    int selectReportBySidCount(Integer sid);

    @Select("SELECT report.id, report.report_name, report.report_question, report.report_date\n" +
            "FROM report, student, answer\n" +
            "WHERE report.id = answer.rid AND student.id = answer.sid\n" +
            "AND student.id = #{sid} AND answer.answer_finish = 0\n" +
            "AND report.report_name LIKE concat('%',#{reportName},'%')\n" +
            "LIMIT #{startIndex},#{pageSize};")
    List<Report> selectReportBySidConditions(Integer sid, String reportName, int startIndex, int pageSize);

    @Select("SELECT COUNT(*)\n" +
            "FROM report, student, answer\n" +
            "WHERE report.id = answer.rid AND student.id = answer.sid\n" +
            "AND student.id = #{sid} AND answer.answer_finish = 0\n" +
            "AND report.report_name LIKE concat('%',#{reportName},'%');")
    int selectReportBySidConditionsCount(Integer sid, String reportName);
}
